<#include "/freemarker/frame.ftl"> 
<#import "/freemarker/componet/enterprise/ligeruiTree.ftl" as enterprise> 
<@frame title="">
<script type="text/javascript">
component.tree.treeNodeOnclick=function(event){
	pk=$(event.target).attr("nodeId");
	var src="mgr/enterprise/department/department!queryDept?dept.id="+pk;
	param={title:"组织机构修改",width:"640",height:"400",close:function(){window.location.reload()}};
	component.dialog.popDialog(src,param);	

}
component.tree.deptValidate=function(field, rules, i, options){
	var nodeCode=$("input[name='dept.code']");
	var parentNodeCode=$("input[name='parent.code']");
	if (nodeCode.val() == parentNodeCode.val()) {
		return "上级部门与本部门编码不能一致";
	}
	
	var node=$("a[nodeCode='"+nodeCode.val()+"']").closest('li');
	if(node.length>0){
		var childNode=node.find("a[nodeCode='"+parentNodeCode.val()+"']");
		if(childNode.length>0){
			return "不能选择下级部门作为上线部门";
		}
	}
}
</script>

	<div class="contentcontainer med left">
            <div class="headings   altheading">
                <h2>部门信息管理</h2>
            </div>
            <div class="contentbox">
            <@s.form id="departmentForm" action="department!addDepartment" method="post" namespace="/mgr/enterprise" theme="simple">
            	<@component.textfield cssClass="validate[required] inputbox smallbox" name="dept.name" label="部门名称"></@component.textfield>
            	<@component.textfield cssClass="validate[required inputbox smallbox" name="dept.code" label="部门编码"></@component.textfield>
            	<@component.popSelect cssClass="validate[funcCall[component.tree.deptValidate]] inputbox smallbox" id="sjbm" tip="" readOnly="true"
						parameter='{"title":"部门选择","src":"mgr/enterprise/pop_dept_tree","width":350,"height":350}'
					 name="parent.code" fieldName="parent.name" label="上级部门"></@component.popSelect>
            	<@component.textfield cssClass="inputbox" name="dept.remark" label="备注"></@component.textfield>
            	<div class="clear"></div>
                <div class='extrabottom' style='text-align: center '>
                	<input type="submit" value="新增" class="btn"  />
                </div>
            </@s.form>
	        </div>
        </div>


		<div class="contentcontainer sml right">
            <div class="headings   altheading">
                <h2 class="left">组织机构树</h2>
            </div>
            <div class="contentbox" style="height:280px;overflow:auto">
            	<@enterprise.deptTree deptTree/>
            </div>
        </div>
</@frame>